package com.software.fanfan.web.controller;

import com.software.fanfan.constant.ResultEnum;
import com.software.fanfan.entity.vo.Result;
import com.software.fanfan.exception.BusinessException;
import com.software.fanfan.serveice.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 与用户相关操作的controller
 *
 * Created by shiyanfei on 2018-01-09.
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result login(HttpServletRequest request, HttpServletResponse response,String loginId, String password){

        if(StringUtils.isBlank(loginId) || StringUtils.isBlank(password)){
            throw new BusinessException(ResultEnum.LOGIN_LOGINIDORPASSWORISNULL);
        }

        return userService.login(loginId,password);
    }

}
